<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>bootstrap form</title>
<script src="${basePath}jquery-1.12.4/jquery-1.12.4.min.js"></script>
<!-- Bootstrap core CSS -->
<link href="${basePath}bootstrap-3.3.7-dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Optional Bootstrap Theme -->
<link href="data:text/css;charset=utf-8,"
	data-href="${basePath}bootstrap-3.3.7-dist/css/bootstrap-theme.min.css"
	rel="stylesheet" id="bs-theme-stylesheet">
<!-- Bootstrap core JavaScript
		<!-- Placed at the end of the document so the pages load faster -->
<script src="${basePath}bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<!-- 分页插件的引  -->
<link
	href="${basePath}pagination-2.0.7/css/pagination.css" rel="stylesheet" />
<script
	src="${basePath}pagination-2.0.7/js/pagination.min.js"></script>

<!-- bootstrap-datetimepicker -->
<link
	href="${basePath}bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css"
	rel="stylesheet" />
<script
	src="${basePath}bootstrap-datetimepicker/js/moment-with-locales.min.js"></script>
<script
	src="${basePath}bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<!-- 弹出框 -->
<link rel="stylesheet" href="${basePath}bootstrap-3.3.7-dist/css/bootstrapEx.css">
<script type="text/javascript" src="${basePath}bootstrap-3.3.7-dist/js/bootstrapEx.js"></script>
<script type="text/javascript">

</script>
<!-- 加载的jquery脚本 -->
<script type="text/javascript">
	// 页面加载完成时就执行查询操作
	$(function(){  
		doAjaxQuery();
	});
	
	// dom加载完成时就执行该方法
	$(function() {
		$('#datetimepicker1,#datetimepicker2').datetimepicker({
			format : 'YYYY-MM-DD HH:mm:ss',
			locale : moment.locale('zh-cn')
		});
	});
</script>

<script type="text/javascript">

var iframeurl = function () { 
	var strr = "StudentInfoModifyDispartchServlet?jp=WEB-INF/logined/studentInfoManager/studentInfoModify";// + getNowDateInt();
	console.info("iframeurl:"+strr);
	return strr; };

/* $(document).ready(function () {
    var Modal3 = InitModal3();
    $("#btn3").click(function () {
        Modal3.show();
    })
}); */

function showModal(iframeUrl){
	var Modal3 = InitModal3(iframeUrl);	
	//var fatherBody = $(window.top.document.body);
	//Modal3.appendTo(fatherBody);
	Modal3.show();
	var i =0;
	// modal关闭时调用的方法
	modal3_Hideend = function () {
	    //alert("Modal关闭完成");
	    doAjaxQuery();
	    console.info("dodal:"+(++i));
	}
}

function InitModal3(iframeUrl) {
	var fatherBody = $(window.top.document.body).find("#mainBody").append('<div id="modal3"></div>');
	console.info("fatherBody:");
	console.info(fatherBody);
    //$(document.body).append('<div id="modal3"></div>');    
    Modal3 = new Modal();
    Modal3.title = "";
    Modal3.renderto = "#modal3";
    Modal3.InitShow = true;
    //{ id: "btn1", text: "保存" },
    Modal3.btns = [ { id: "closebtn",text:"修改" }]
    //Modal3.setHeigth("800px");
    tab1 = new Tab();
    Modal3.OnfirstInited = function (thismodal) {
        tab1.tabs = [{
            id: "tabs1", title: "用户信息修改", active: true, isiframe: true, url: iframeUrl
        }];
        tab1.renderto = thismodal.body;
        tab1.Init();
        $("#closebtn").click(function () {
            //alert("点击保存按钮");
            // 调用关闭按钮的click事件可以关闭弹出框
            //$("#closebtn").click();
            //console.info("tab1:");
            //console.info($('#tabs1> iframe').contents().find("#btnSave"));
                       
            $('#tabs1> iframe').contents().find("#formMod").submit();
            /* console.info("document.body");
            console.info($(document.body).find("#myForm"));          
            $(document.body).find("#btnQuery").click(); */
         	// 调用关闭按钮的click事件可以关闭弹出框
            //$("#closebtn").click();
        })
    }
    return Modal3;
}





	function doAjaxQuery() {
		$.ajax({
			type : "POST", // 请求的类型 get/post
			url : "${basePath}StudentInfoAjaxQueryServlet", // 服务器url
			dataType : "json", // 服务器返回的数据类型
			data : $("#myForm").serialize(),
			success : function(data) { // 成功之后的回调函数
				// 调用分页插件的分页的行为方法
				//console.info("data:");
				//console.info(data);
				// 当查询数据不为空的时候进行分页处理
				if(data !=null && data.length >0){
					// 分页处理
					doPaging(data);
				}else{
					// 查询结果集为空时，情况显示的table内容
					$("#tbShow").html("");
				}
			}
		});
	}
	
	function doDeleteAjaxQuery(delIndex) {
		//alert("delete:"+delIndex);
		// 将删除记录的id值赋值给隐藏控件，通过form表单发送到后台
		$("#delIndex").val(delIndex);
		$.ajax({
			type : "POST", // 请求的类型 get/post
			url : "${basePath}StudentInfoAjaxDeleteServlet", // 服务器url
			dataType : "json", // 服务器返回的数据类型
			data : $("#myForm").serialize(),
			success : function(data) { // 成功之后的回调函数
				// 调用分页插件的分页的行为方法
				console.info("data in ajax callback:");
				console.info(data);
				// 当查询数据不为空的时候进行分页处理
				if(data !=null && data.length >0){
					// 分页处理
					doPaging(data);
				}else{
					// 查询结果集为空时，情况显示的table内容
					$("#tbShow").html("");
				}
			}
		});
	}
	
	// 调用分页控件
	function doPaging(pageDatas) {
		// 调用分页插件的分页处理的方法
		$('#pager').pagination({
			dataSource : pageDatas, // 分页的数据源			
			pageSize : 3, // 每页有几条记录
			showGoInput : true, // 是否显示输入页面处理
			showGoButton : true,
			callback : function(data, pagination) { // 点击分页插件页数时的回调方法
				// 注意：dataSource数据源为空时，不会执行会调用函数
				// 调用分页数据的解析处理方法
				parseJsonData(data);
			}
		})
	}
	
	// json解析处理函数
	function parseJsonData(data){
		//解析的结果串
		var strResult = "";
		// 使用jquery解析json对象，因为json是一个list数据结构，是一个数组结构，所以使用each函数进行解析
		// 如果json返回的是一个对象，则可以先将该对象转换为数组结构再进行遍历，转换方式： "["+data+"]"
		$.each( data, function(index, eachVal){ // 每个eachVal就是list中的一个bean对象
			strResult +="<tr>";	
			
			strResult +="<th scope='row'>";	
			strResult +=index+1;	
			strResult +="</th>";
			
			strResult +="<td>";	
			strResult +=eachVal.stu_name;	
			strResult +="</td>";	
			
			strResult +="<td>";	
			strResult +=eachVal.stu_sex;	
			strResult +="</td>";
			
			strResult +="<td>";	
			strResult +=eachVal.stu_birthday;	
			strResult +="</td>";
			
			strResult +="<td>";	
			strResult +=eachVal.stu_address;	
			strResult +="</td>";
			
			strResult +="<td>";	
			strResult +=eachVal.stu_tel;	
			strResult +="</td>";
			
			strResult +="<td>";	
			strResult +=eachVal.stu_department;	
			strResult +="</td>";
			
			strResult +="<td><img style='width: 30px; heigth: 30px;' src='";	
			strResult +=eachVal.stu_img;	
			strResult +="'></td>";
			// 修改列
			strResult +="<td>";	
			/* strResult +="<a href='StudentInfoModifyDispartchServlet?jp=WEB-INF/logined/studentInfoManager/studentInfoModify&sid="+eachVal.stu_id+
					"'>	<span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></a>";	 */
					strResult +="<a id='showM' href='javascript:showModal(\"StudentInfoModifyDispartchServlet?jp=WEB-INF/logined/studentInfoManager/studentInfoModify&sid="+eachVal.stu_id+
					"\");'><span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></a>";	
					strResult +="</td>";
			// 删除
			strResult +="<td>";	
			strResult +="<a href='javascript:doDeleteAjaxQuery("+eachVal.stu_id+");' onclick='return confirm(\"是否要删除["
				+eachVal.stu_name + "]该记录\");'><span class='glyphicon glyphicon-trash' aria-hidden='true' ></span></a>";
			strResult +="</td>";
			
			strResult +="</tr>";
			});
		
		// 将解析的结果内容，添加到显示的控件中
		$("#tbShow").html(strResult);
	}
</script>

</head>

<body>
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-12">
				<div class="row">
					<div class="col-md-2"></div>
					<div class="col-md-8">
						<form class="form-horizontal" id="myForm">
							<div class="form-group">
								<!-- 隐藏控件：删除记录的id -->
								<input type="hidden" id="delIndex" name="delIndex">
							</div>
							<div class="form-group">
								<label for="inputEmail3" class="col-sm-2 control-label">姓名</label>
								<div class="col-sm-4">
									<input type="text" class="form-control" id="stuName"
										name="stu_name" placeholder="请输入学生姓名">
								</div>

								<label for="inputEmail3" class="col-sm-2 control-label">性别</label>
								<div class="col-sm-4">
									<label class="radio-inline"> <input type="radio"
										id="stusex2" name="stu_sex" value="女"> 女
									</label> <label class="radio-inline"> <input type="radio"
										id="stusex2" name="stu_sex" value="男"> 男
									</label>
									<label class="radio-inline"> <input type="radio"
										id="stusex3" name="stu_sex" value="" checked > 性别不限
									</label>
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">出生日期</label>
								<div class="col-sm-4">
									<!-- <input type="text" class="form-control" id="stuBirthday"
										name="stuBirthday" placeholder="请选择出生日期"> -->
									<div class='input-group date' id='datetimepicker1'>
										<input type='text' class="form-control" id="stuBirthday"
											name="stu_birthday" /> <span class="input-group-addon">
											<span class="glyphicon glyphicon-calendar"></span>
										</span>
									</div>
									<div class='input-group date' id='datetimepicker2'>
										<input type='text' class="form-control" id="stuBirthday2"
											name="stu_birthday2" /> <span class="input-group-addon">
											<span class="glyphicon glyphicon-calendar"></span>
										</span>
									</div>
								</div>

								<label for="inputPassword3" class="col-sm-2 control-label">地址</label>
								<div class="col-sm-4">
									<input type="text" class="form-control" id="stuAddress"
										name="stu_address" placeholder="请输入地址">
								</div>
							</div>
							<div class="form-group">
								<label for="inputPassword3" class="col-sm-2 control-label">电话</label>
								<div class="col-sm-4">
									<input type="text" class="form-control" id="stuTel"
										name="stu_tel" placeholder="请输入电话">
								</div>

								<label for="inputPassword3" class="col-sm-2 control-label">系别</label>
								<div class="col-sm-4">
									<select class="form-control" id="stuDepartment"
										name="stu_department">
										<option></option>
										<option value="1">计算机</option>
										<option value="2">电信</option>
										<option value="3">机电</option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-offset-4 col-sm-4">
									<button type="button" id="btnQuery" class="btn btn-default" 
									onclick = "doAjaxQuery()">查询</button>
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									<button type="reset" class="btn btn-default">重置</button>
								</div>
							</div>
						</form>
					</div>
					<div class="col-md-2"></div>
				</div>
			</div>
		</div>
	</div>
	<div class="bs-example" data-example-id="hoverable-table">
		<table class="table table-hover">
			<thead>
				<tr>
					<th>序号</th>
					<th>姓名</th>
					<th>性别</th>
					<th>出生日期</th>
					<th>地址</th>
					<th>电话</th>
					<th>系别</th>
					<th>头像</th>
					<th>修改</th>
					<th>删除</th>
				</tr>
			</thead>
			<tbody id="tbShow">
				
			</tbody>
		</table>
		<div id="pager">
				<!-- pagination所需容器 -->
				<div class="m-pagination"></div>
			</div>
	</div>
</body>

</html>